package cn.itamt.utils.grouploader {
	import flash.display.Loader;
	import flash.net.URLLoader;		

	/**
	 * TODO:完善对文件类型的支持.
	 * 一个加载项
	 * @author tamt
	 */
	public class GroupPreloadItem {
		public static const TYPE_XML : String = 'xml';
		public static const TYPE_SWF : String = 'swf';		public static const TYPE_IMG : String = 'img';

		private var _url : String;

		public function get url() : String {
			return _url;
		}

		//类型, 如swf, xml, 其他等.
		private var _type : String;

		public function get type() : String {
			return _type;
		}

		private var _preventCache : Boolean;

		public function get preventCache() : Boolean {
			return _preventCache;
		}

		private var _dsn : String;

		public function get dsn() : String {
			return _dsn;
		}

		/**
		 * @param url			文件地址
		 * @param type			类型: GroupPreloadItem.TYPE_XML, GroupPreloadItem.TYPE_SWF, GroupPreloadItem.TYPE_IMG
		 * @param preventCache 	是否避免缓存, 将在url后加个随机的参数.
		 * @param dsn			说明性的文字, 比如"兵种建筑xml数据."
		 */
		public function GroupPreloadItem(url : String, type : String, preventCache : Boolean = false, dsn : String = null,  onComplete : Function = null) : void {
			this._url = url;
			
			switch(type) {
				case TYPE_SWF:
					this._type = TYPE_SWF;
					break;
				case TYPE_XML:
					this._type = TYPE_XML;
					break;
				case TYPE_IMG:
					this._type = TYPE_IMG;
					break;
				default:
					break;
			}
			
			this._preventCache = preventCache;
			
			this._dsn = dsn;
		}

		private var _loader : *;

		internal function setLoader(loader : *) : void {
			if(this._type == TYPE_SWF || this._type == TYPE_IMG) {
				if(loader is Loader) {
					_loader = loader;
				}
			} else {
				if(loader is URLLoader) {
					_loader = loader;
				}
			}
		}

		public function disose() : void {
			_loader = null;
		}
	}
}
